<?php

namespace App\Http\Controllers;

use App\News;
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\Config;

class NewsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function peiXunBan()
    {
        $news = $this->_inner(Config::get('constants.PARENT_SCHOOL_TYPE1')['key']);
        $data = array(
            'newsList' => $news
        );
        return view("newslist",$data);
    }

    public function ketang(){
        $news = $this->_inner(Config::get('constants.PARENT_SCHOOL_TYPE2')['key']);
        $data = array(
            'newsList' => $news
        );
        return view("newslist",$data);
    }

    public function zaojiao(){
        $news = $this->_inner(Config::get('constants.PARENT_SCHOOL_TYPE3')['key']);
        $data = array(
            'newsList' => $news
        );
        return view("newslist",$data);
    }

    public function zixun(){
        $news = $this->_inner(Config::get('constants.PARENT_SCHOOL_TYPE4')['key']);
        $data = array(
            'newsList' => $news
        );
        return view("newslist",$data);
    }

    private function _inner($type){
        $pageSize = 10;
        $news = News::where('isDeleted',0)->where('type',$type)->paginate($pageSize);

        return $news;
    }

    public function detail(Request $request){
        $id = $request->id;
        $id = ($id) ? intval($id) : 0;
        if (!$id) {
            return redirect("/");
        }

        $news = News::where('id',$id)->first();

        $data = array();
        if ($news) {
            $data['news'] = $news;
        }
        return view('news',$data);
    }
}
